/*
 * Created on 20 ao�t 2005
 *
 */

package picoevo.gp.evolution;

import picoevo.core.evolution.VariationOperator;
import picoevo.core.representation.EvolutionObject;
import picoevo.gp.representation.Element_Node_TreeGP_Root;
import picoevo.toolbox.Dictionary;

/**
 * this variation operator may be attached (exclusively) to a root node element
 * operator is applied with proba depending on ReInitRate paramater
 */
public class VariationOperator_Element_TreeGP_ReInitialize extends VariationOperator {

	public VariationOperator_Element_TreeGP_ReInitialize(String __name) {
		super(__name);
	}

	VariationOperator_Element_TreeGP_ReInitialize(String __name, double __operatorRate) {
		super(__name, __operatorRate);
	}

	@Override
	public void applyOperator(EvolutionObject __element) {
		Element_Node_TreeGP_Root element = (Element_Node_TreeGP_Root) __element;

		if (element.getTemplate().getDoubleProperty("ReInitRate") < Math.random()) {
			element.resetSuccessorConnections(); // successors should be
			// garbage collected.
			if (element.getTemplate().getIntProperty("MaxInitDepth") <= 1)
				element.performInitialisation();
			else
				element.performInitialisation(element.getTemplate().getIntProperty("MaxInitDepth"), Dictionary.growMethod, true);
		}
	}
}